﻿using Dapper;
using Estsh.Core.Base;
using Estsh.Core.Dapper;
using Estsh.Core.Model.EnumUtil;
using Estsh.Core.Models;
using Estsh.Core.Repositories;
using Estsh.Core.Wms.IRepositories;
using System.Data;
using System.Text;

namespace Estsh.Core.Wms.Repositories
{
    /// <summary>
    /// 库存查询
    /// </summary>
    public class StockQueryRepository : BaseRepository<BaseEntity>, IStockQueryRepository
    {
        public StockQueryRepository(DapperDbContext _dapperDbContext) : base(_dapperDbContext)
        {

        }
        /// <summary>
        /// 获取库存查询信息
        /// </summary>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        public List<SysStock> GetStockQueryList(string part_spec)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                dbConn.Open();
                StringBuilder sql = new StringBuilder(1024);
                sql.Append("select locate_name,sum(qty) qty,count(1) carton_qty from sys_stock (nolock) where part_spec=@part_spec and locate_name <> '' and locate_name is not null and enabled='Y' group by locate_name   ");
                DynamicParameters parameters = new DynamicParameters();
                parameters.Add("@part_spec", part_spec);

                List<SysStock> sysStocks = dbConn.Query<SysStock>(sql.ToString(), parameters).ToList();
                return sysStocks;
            }
        }

    }
}
